<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%--
  Created by IntelliJ IDEA.
  User: lzy
  Date: 2018/11/2
  Time: 11:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
    <title>Employee list</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <%
        pageContext.setAttribute("APP_PATH", request.getContextPath());
    %>
    <!-- Bootstrap -->
    <link href="${APP_PATH}/static/bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet">
    <%--jQuery--%>
    <script src="${APP_PATH}/static/jQuery/jquery.min-1.9.1.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="${APP_PATH}/static/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
    <style>
        body {
            padding-top: 60px;
        }
    </style>
    <script type="text/javascript">
        $(function () {
            $(".delete").click(function () {
                var label = $(this).next(":hidden").val();
                var flag = confirm("确定要删除" + label + "的信息么？");
                if (flag) {
                    var url = $(this).attr("href");
                    $("#_form").attr("action", url);
                    $("#_method").val("DELETE");
                    $("#_form").submit();
                }
                return false;
            })
        })
    </script>
</head>
<body>
<form action="" method="post" id="_form">
    <input type="hidden" id="_method" name="_method">
</form>
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
    <div class="container">
        <div class="navbar-header">
            <a href="#" class="navbar-brand">Welcome to SSSP Test</a>
        </div>
    </div>
</nav>
<c:if test="${page == null || page.numberOfElements == 0}">
    <p>没有任何记录</p>
</c:if>
<div class="container">
    <div class="table-responsive">
        <c:if test="${page != null && page.numberOfElements > 0}">
            <table class="table table-bordered table-hover">
                <tr class="warning">
                    <td>ID</td>
                    <td>LastName</td>
                    <td>Email</td>
                    <td>Birth</td>
                    <td>CreateTime</td>
                    <td>Department</td>
                    <td>Edit</td>
                    <td>Delete</td>
                </tr>
                <c:forEach items="${page.content}" var="emp">
                    <tr>
                        <td>${emp.id}</td>
                        <td>${emp.lastName}</td>
                        <td>${emp.email}</td>
                        <td>
                            <fmt:formatDate pattern="yyyy-MM- dd" value="${emp.birth}"/>
                        </td>
                        <td>
                            <fmt:formatDate pattern="yyyy-MM-dd HH:mm:ss" value="${emp.createTime}"/>
                        </td>
                        <td>${emp.department.departmentName}</td>
                        <td><a href="${pageContext.request.contextPath}/emp/${emp.id}">Edit</a></td>
                        <td>
                            <a href="${pageContext.request.contextPath}/emp/${emp.id}" class="delete">Delete</a>
                            <input type="hidden" value="${employee.lastName}">
                        </td>
                    </tr>
                </c:forEach>
                <tr class="info text-center">
                    <td colspan="8">
                        共${page.totalElements}条记录 &nbsp;
                        共${page.totalPages}页&nbsp;
                        当前第${page.number+1}页&nbsp;
                        <a href="?pageNo=${page.number+1-1}">上一页</a>&nbsp;
                        <a href="?pageNo=${page.number+1+1}">下一页</a>
                    </td>
                </tr>
            </table>
        </c:if>
    </div>
</div>
</body>
</html>
